package com.usian.controller;

import com.usian.articles.Articles;
import com.usian.column.Vermicelli;
import com.usian.service.VermicelliService;
import com.usian.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping("/app/users/concerns")
public class VermicelliController {
    @Autowired
    private VermicelliService vermicelliService;

    @RequestMapping("/contents/{id}")
    public List<Articles> getVermicelliList(@PathVariable("id") Integer id){
        List<Vermicelli> vermicelliList = vermicelliService.getVermicelliList(id);
        if (vermicelliList==null){
            return null;
        }
        ArrayList<Articles> articlesList = new ArrayList<>();
        for (Vermicelli vermicelli : vermicelliList) {
            User user= vermicelliService.selectUserById(vermicelli.getConcernId());
          List<Articles> articles1= vermicelliService.selectArticles(vermicelli.getConcernId());
            for (Articles articles : articles1) {
                articles.setUname(user.getName());
                articles.setImg(user.getImage());
                articlesList.add(articles);
            }

        }
        return articlesList;
    }
}